package mc

import (
	"gitee.com/dreamwood/ez-go/db/mgo"
)

const (
	HouseEventNew           = "pm.HouseNew"
	HouseEventBeforeCreate  = "pm.HouseBeforeCreate"
	HouseEventBeforeUpdate  = "pm.HouseBeforeUpdate"
	HouseEventBeforeSave    = "pm.HouseBeforeCreate pm.HouseBeforeUpdate"
	HouseEventAfterCreate   = "pm.HouseAfterCreate"
	HouseEventAfterUpdate   = "pm.HouseAfterUpdate"
	HouseEventAfterSave     = "pm.HouseAfterCreate pm.HouseAfterUpdate"
	HouseEventDelete        = "pm.HouseDelete"
	HouseAccessControlEvent = "pm.HouseAccessControl"
)

func GetHouseConfig() *mgo.DocConfig {
	return House_Config
}

var House_Config *mgo.DocConfig

func init() {
	House_Config = NewHouseConfig()
}
func NewHouseConfig() *mgo.DocConfig {
	return &mgo.DocConfig{
		ContainerKey: "pm.House",
		Fields: []string{
			"name", "area", "community", "type", "owner", "car", "note",
		},
		RelationFields: []string{
			"community", "type", "owner", "car",
		},
		RelationConfigs: map[string]*mgo.DocRelation{
			"community": {
				Config:     GetCommunityConfig,
				DocName:    "Community",
				JoinType:   "O",
				KeyInside:  "communityId",
				KeyOutSide: "id",
			},
			"type": {
				Config:     GetHouseTypeConfig,
				DocName:    "HouseType",
				JoinType:   "O",
				KeyInside:  "typeId",
				KeyOutSide: "id",
			},
			"owner": {
				Config:     GetOwnerConfig,
				DocName:    "Owner",
				JoinType:   "MM",
				KeyInside:  "ownerIds",
				KeyOutSide: "id",
			},
			"car": {
				Config:     GetCarConfig,
				DocName:    "Car",
				JoinType:   "MM",
				KeyInside:  "carIds",
				KeyOutSide: "id",
			},
		},
		FieldFilter: map[string]*mgo.DocFieldFilter{
			"default": {
				Select: []string{},
				Omit:   []string{},
			},
		},
	}
}
